package cn.edu.hust.youth.tzb.servlet.student;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.edu.hust.youth.tzb.dao.TeamDAO;
import cn.edu.hust.youth.tzb.model.Student;

public class Deleteteam extends HttpServlet {
	private static final String CONTENT_TYPE = "text/html; charset=GBK";
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HttpSession session = request.getSession(true);
        response.setContentType(CONTENT_TYPE);
        String teamid=request.getParameter("teamid");
        Student s=(Student)request.getSession().getAttribute("STUDENT");
        TeamDAO td=new TeamDAO();
        try {
			td.deleteTeam(s.getId(),teamid);
			request.setAttribute("error", "deleteteam_ok");
		} catch (SQLException e) {
			e.printStackTrace();
			request.setAttribute("error", "deleteteam_false");
		}
        String target = "/student/viewteam.jsp";
        RequestDispatcher rd = this.getServletContext().getRequestDispatcher(target);
        rd.forward(request,response);
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(req, resp);
	}

}
